/**

 @Name：layuiAdmin（iframe版） 消息中心
 @Author：贤心
 @Site：http://www.layui.com/admin/
 @License：LPPL

 */


layui.define(['admin', 'table', 'util'], function (exports) {
    var $ = layui.$
        , admin = layui.admin
        , table = layui.table
        , element = layui.element
        , util = layui.util;
    var addtime = function(d){
        return util.toDateString(d.addtime*1000,'yyyy-MM-dd HH:mm:ss');
    };

    var DISABLED = 'layui-btn-disabled'
        //区分各选项卡中的表格
        , tabs = {
            no: {
                text: '未读消息'
                , id: 'no'
            }
            , yes: {
                text: '已读消息'
                , id: 'yes'
            }
        };

    //未读消息
    table.render({
        elem: '#no',
        method: 'post'
        , url: '/shengteng/wmsg/index/status/0.html' //模拟接口
        , cols: [[
            {field: 'headimgurl', title: '头像', width: 80, templet: '#avatar'}
            , {field: 'nickname', title: '昵称', width: 120}
            , {field: 'content', title: '消息', width: 120}
            , {field: 'create_time', title: '时间', width: 170,templet: addtime}
            ,{width: 160, align: 'center', toolbar: '#action'}
        ]]
    });
    //监听工具条
    table.on('tool(no)', function (obj) {
        var data = obj.data;
        var openid = data.openid;
        if (obj.event === 'reply') {
            var index = layer.open({
                type: 2,
                content: '/shengteng/wmsg/reply/openid/' + openid,
                area: ['300px', '300px'],
                maxmin: true
            });
            layer.full(index);
        }
    });

    //已读消息
    table.render({
        elem: '#yes',
        method: 'post'
        , url: '/shengteng/wmsg/index/status/1.html' //模拟接口
        , cols: [[
            {field: 'headimgurl', title: '头像', width: 180, templet: '#avatar1'}
            , {field: 'nickname', title: '昵称', width: 120}
            , {field: 'content', title: '消息', width: 120}
            , {field: 'create_time', title: '时间', width: 170,templet: addtime}
            ,{width: 160, align: 'center', toolbar: '#action'}
        ]]
    });
    //监听工具条
    table.on('tool(yes)', function (obj) {
        var data = obj.data;
        var openid = data.openid;
        if (obj.event === 'reply') {
            var index = layer.open({
                type: 2,
                content: '/shengteng/wmsg/reply/openid/' + openid,
                area: ['300px', '300px'],
                maxmin: true
            });
            layer.full(index);
        }
    });
    exports('wmsg', {});
});
